<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;

class UserController extends LiaoBaseController
{
    public function __construct()
    {
        $this->model      = '\App\User';
        $this->fields_all = [
            'users.id'         => [
                'show' => '序号',
            ],
            'users.name'       => [
                'show'   => '昵称',
                'search' => "users.name like CONCAT('%', ?, '%')"
            ],
            'email'      => [
                'show' => '邮箱',
            ],
            'password'   => [
                'show' => '密码',
                'edit' => false,
            ],
            'created_at' => [
                'show' => '创建时间',
            ],
            'updated_at' => [
                'show' => '更新时间',
            ],
        ];

        $this->fields_show   = ['users.id', 'users.name', 'email', 'created_at'];
        $this->fields_edit   = ['users.name', 'email', 'password'];
        $this->fields_create = ['users.name', 'email', 'password'];
        parent::__construct ();
        //dd(action('\\'.$this->controller.'@index'));
    }
    public function edit($id)
    {
        $model = new $this->model;
        $models = $model->find ($id);
        unset($models->password);
        return View::make ('liao.edit', [
            'model' => $models,
        ]);
    }
    public function update($id)
    {
        $model            = new $this->model;
        $model            = $model->find ($id);
        $data             = Input::all ();
        $data['password'] = md5 ($data['password']);
        $model->fill ($data);
        $model->save ();

        return Redirect::to (action ($this->controller . '@index'));
    }
}
